package com.company;


    import java.sql.*;

    public class Main {

        public static void main(String[] args)

        {
            //驱动
            String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

            String dbURL = "jdbc:sqlserver://localhost:1433;+DatabaseName=xscjjava";

            String userName = "sa";

            String userPwd = "123456";

            Connection dbConn = null;

            try

            {

                Class.forName(driverName);

                dbConn = DriverManager.getConnection(dbURL, userName, userPwd);

                System.out.println("连接数据库成功");

            }

            catch (Exception e)

            {

                e.printStackTrace();

                System.out.print("连接失败");

            }

        }

    }


